package main

import (
	"github.com/mattn/go-colorable"
	"github.com/sirupsen/logrus"
	prefixed "github.com/x-cray/logrus-prefixed-formatter"
	"os"
)

func init() {
	//定义日志格式
	//go get github.com/x-cray/logrus-prefixed-formatter
	//go get github.com/lestrrat/go-file-rotatelogs
	formatter := &prefixed.TextFormatter{} //定义文本输出
	//控制台高亮输出
	formatter.ForceColors = true
	formatter.DisableColors = false
	formatter.FullTimestamp = true
	formatter.ForceFormatting = true
	formatter.SetColorScheme(&prefixed.ColorScheme{
		InfoLevelStyle:  "green",
		WarnLevelStyle:  "yellow",
		ErrorLevelStyle: "red",
		FatalLevelStyle: "41",
		PanicLevelStyle: "41",
		DebugLevelStyle: "blue",
		PrefixStyle:     "cyan",
		TimestampStyle:  "37",
	})
	formatter.TimestampFormat = "2022-11-17.10:17:25.000000"
	logrus.SetFormatter(formatter)
	logrus.SetOutput(colorable.NewColorableStdout())
	//日志级别
	if os.Getenv("log.debug") == "true" {
		logrus.SetLevel(logrus.DebugLevel)
	}
	//SetLineNumlogrusGook()
	//LogPath := path.Join(logPath, logFileName)
	//设置滚动日志输出writer
	//writer, err := rotatelogs.New(
	//	strings.TrimSuffix(LogPath, ".log")+"%Y%m%d%H.log",
	//	rotatelogs.WithLinkName(LogPath),          //生成软链，只想最新日志文件
	//	rotatelogs.WithMaxAge(maxAge),             //文件最大保存时间
	//	rotatelogs.WithRotationTime(rotationTime), //日志切割时间间隔
	//)
	//if err != nil {
	//	logrus.Errorf("随便写:%v\n", err)
	//}
	//lfHook := lfshook.NewHook(lfshook.WriterMap{
	//	logrus.DebugLevel: writer, //为不同级别设置不同的输出目标
	//	logrus.InfoLevel:  writer,
	//	logrus.WarnLevel:  writer,
	//	logrus.ErrorLevel: writer,
	//	logrus.FatalLevel: writer,
	//	logrus.PanicLevel: writer,
	//}, logrus.StandardLogger().Formatter)
	//logrus.AddHook(lfHook)

	//日志文件和滚动配置
	logrus.Info("测试")
	logrus.Debug("我是测试")
}
